package com.szjlxh.data.net;

import com.szjlxh.data.entity.SunDataBean;
import com.szjlxh.data.execption.NetworkConnectionException;
import com.szjlxh.data.utils.GsonObjectFormatter;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by liutao on 16/3/18.
 */
public class BaseWeatherInfoApiImpl implements BaseWeatherInfoApi {

    public BaseWeatherInfoApiImpl() {

    }

    @Override
    public Observable<SunDataBean> sunDownRiseInfo() {
        return Observable.create(new Observable.OnSubscribe<SunDataBean>() {
            @Override
            public void call(Subscriber<? super SunDataBean> subscriber) {
                try {
                    String resString = ApiConnection.createGET(ConstantUrl.SUN_DOWN_UP_URL).requestSyncCall();
                    subscriber.onNext(new GsonObjectFormatter<SunDataBean>(resString).getObjectFromType(SunDataBean.class));
                } catch (Exception e) {
//                    e.printStackTrace();
                    subscriber.onError(e.getCause());
                }
            }
        });
    }
}
